package com.marvels.approve.process.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fintech.common.util.SolrUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.marvels.approve.common.dto.AttachmentInfoDTO;
import com.marvels.approve.common.dto.EstateInfoDTO;
import com.marvels.approve.common.dto.FakeInfoDTO;
import com.marvels.approve.common.dto.InsuranceCheckDTO;
import com.marvels.approve.common.dto.InsurancePolicyDTO;
import com.marvels.approve.common.dto.LoanApplyContactInfoDTO;
import com.marvels.approve.common.dto.LoanContactCheckDTO;
import com.marvels.approve.common.dto.LoanExtInfoDTO;
import com.marvels.approve.common.dto.LoanFeelInfoDTO;
import com.marvels.approve.common.dto.PhoneCheckDTO;
import com.marvels.approve.common.dto.RiskCheckInfoDTO;
import com.marvels.approve.common.dto.StateDetailedDTO;
import com.marvels.approve.common.dto.TrickCheckInfoDTO;
import com.marvels.approve.common.service.ISysUserService;
import com.marvels.approve.consum.ApproveConsumerLoanApplyApi;
import com.marvels.approve.consum.ApproveConsumerSystemApi;
import com.marvels.approve.credit.service.ApproveThirdCreditReportService;
import com.marvels.approve.loan.dao.McamAutoDecisionMapper;
import com.marvels.approve.loan.dto.LoanExtDataDTO;
import com.marvels.approve.loan.dto.McamAutoDecisionWithBLOBs;
import com.marvels.approve.loan.dto.McamLoanApplyInfoDTO;
import com.marvels.approve.loan.dto.McsmSystemParam;
import com.marvels.approve.manager.dto.LoanStateEnum;
import com.marvels.approve.manager.dto.OpinionTypeDTO;
import com.marvels.approve.manager.service.IOpinionTypeService;
import com.marvels.approve.mqueues.service.ApproveLoanApplySynchronizeApi;
import com.marvels.approve.process.api.ApplyProvideConsumerApi;
import com.marvels.approve.process.api.LoanBasicDataConsumerApi;
import com.marvels.approve.process.dao.ILoanApplyCaseDao;
import com.marvels.approve.process.dao.TaskProcessDao;
import com.marvels.approve.process.dto.LaAttachAtmeTypeViewDTO;
import com.marvels.approve.process.dto.LoanApplyCaseDTO;
import com.marvels.approve.process.dto.SysUserDTO;
import com.marvels.approve.process.service.TaskProcessService;
import com.marvels.common.constants.CaseNodeConstant;
import com.marvels.common.constants.MarvelsConstant;
import com.marvels.common.dto.BasicDataDTO;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.dto.UserDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.CacheUtils;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.loanapply.api.MclaLinkmanMobileApi;
import com.marvels.loanapply.dto.MclaLoanApplyLinkmanDTO;

@Service
public class TaskProcessServiceImpl implements TaskProcessService {
	@Autowired
	private TaskProcessDao taskProcessDao;
	
	@Autowired
	private ILoanApplyCaseDao loanApplyCaseDao;
	@Autowired
	private LoanBasicDataConsumerApi loanBasicDataConsumerApi;
	
	@Autowired
	private ISysUserService sysUserApi;
	
	@Autowired
	private ApproveConsumerSystemApi consumerSystemApi;
	
	@Autowired
	private IOpinionTypeService opinionTypeService;
	@Autowired
	private ApplyProvideConsumerApi applyProvideConsumerApi;
	@Autowired
	private McamAutoDecisionMapper mcamAutoDecisionMapper;
	@Autowired
	private ApproveConsumerLoanApplyApi consumerLoanApplyApi;
	@Autowired
	private MclaLinkmanMobileApi mclaLinkmanMobileApi;
    @Autowired
    private ApproveThirdCreditReportService thirdCreditReportService;
	
	public McamLoanApplyInfoDTO getLoanInfo(String loanId) throws MarvelsBusinessException {
		McamLoanApplyInfoDTO dto=selectLoanApplyInfo(loanId);
		dto.setCaseDTO(loanApplyCaseDao.selectByLoanId(loanId));
		return selectLoanApplyInfo(loanId);
	}
	
	@Value("${solr.url}")
	private String solrUrl;
	
	/**
	 * 查询进件信息
	 * @param loanId
	 * @return
	 * @throws MarvelsBusinessException
	 */
	private McamLoanApplyInfoDTO selectLoanApplyInfo(String loanId) throws MarvelsBusinessException{
		if(StringUtils.isEmpty(loanId)){
			throw new MarvelsBusinessException("loanId 为空");
		}
		McamLoanApplyInfoDTO loanApplyInfo = taskProcessDao.selectLoanApplyInfo(loanId);
		if(loanApplyInfo == null){
			throw new MarvelsBusinessException("查无此信息, loanId="+loanId);
		}
		//获取自动审核结果
		try {
			MarvelsLogUtil.getInstance().info("loanId[" + loanId + "]，开始获取自动审核结果");
			McamAutoDecisionWithBLOBs mcamAutoDecisionWithBLOBs = mcamAutoDecisionMapper.selectByLoanId(loanId);
			if(mcamAutoDecisionWithBLOBs != null){
				MarvelsLogUtil.getInstance().info("loanId[" + loanId + "]，获取自动审核结果：" + mcamAutoDecisionWithBLOBs.getStatus());
				loanApplyInfo.setAutoDecisionStatus(mcamAutoDecisionWithBLOBs.getStatus());
			}else{
				MarvelsLogUtil.getInstance().info("loanId[" + loanId + "]，获取自动审核结果空");
			}
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("loanId[" + loanId + "]，获取自动审核结果异常：", e);
		}
		
		try {
			//不是审核中的单，才去查还款状态信息
			if(!loanApplyInfo.getStatus().equals("Z00") && !loanApplyInfo.getStatus().equals("Z01") && !loanApplyInfo.getStatus().equals("K02")){
				LoanExtDataDTO loanExtDataDTO = new LoanExtDataDTO();
				loanExtDataDTO.setLoanId(loanId);
				LoanExtDataDTO result = consumerLoanApplyApi.selectLoanExtData(loanExtDataDTO);
				MarvelsLogUtil.getInstance().info("loanId[" + loanId + "]，LoanExtDataDTO结果：" + JSONObject.toJSONString(result));
				if(result != null){
					loanApplyInfo.setLoanDate(result.getLoanDate());
					//逾期了
					if(result.getStatus() != null && result.getStatus() == 1){
						loanApplyInfo.setStateName(LoanStateEnum.OVERDUE.getStateName());
					}else{
						loanApplyInfo.setStateName(LoanStateEnum.getNameByState(result.getStateId()));
					}
				}
			}else{
				loanApplyInfo.setStateName(LoanStateEnum.getNameByState(loanApplyInfo.getStatus()));
			}
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("loanId[" + loanId + "]，获取LoanExtDataDTO异常：", e);
		}
		return loanApplyInfo;
	}
	
	@Override
	public McamLoanApplyInfoDTO getLoanDetail(String loanId) throws MarvelsBusinessException {
		McamLoanApplyInfoDTO loanApplyInfo = selectLoanApplyInfo(loanId);
		//获取保单信息
		InsurancePolicyDTO insurancePolicy  = taskProcessDao.selectInsurancePolicyInfo(loanId);
		loanApplyInfo.setInsurancePolicy(insurancePolicy);
		//获取保单核录信息
		InsuranceCheckDTO insuranceCheck = taskProcessDao.selectInsuranceCheckInfo(loanId);
		loanApplyInfo.setInsuranceCheck(insuranceCheck);
		//获取录音文件
		List<AttachmentInfoDTO> attachmentList = taskProcessDao.selectAttachmentList(loanId, "V");
		loanApplyInfo.setAttachmentList(attachmentList);
		//获取房产信息
		List<EstateInfoDTO> estateList = taskProcessDao.selectEstateList(loanId);
		loanApplyInfo.setEstateList(estateList);
		return loanApplyInfo; 
	}

	/**
	 * 先统一从缓存中取，有一个没有就远程获取
	 */
	@Override
	public MarvelsResultDTO getBasicDatas() throws MarvelsBusinessException {
		boolean callFlag = false;
		List<String> params = new ArrayList<String>();
		params.add(MarvelsConstant.PURPOSE_LIST);
		params.add(MarvelsConstant.PAYMENT_MODE_LIST);
		params.add(MarvelsConstant.LIFE_INSURANCE_TYPE_LIST);
		params.add(MarvelsConstant.INSURANCE_TYPE_LIST);
		params.add(MarvelsConstant.INSURANCE_STATUS_LIST);
		params.add(MarvelsConstant.INSURANCE_COMPANY_LIST);
		Map<String,List<BasicDataDTO>> map = getCacheBasicDatas(params);
		if(map == null || map.size() != params.size()){
			callFlag = true;
		}
		if(!callFlag){
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), map);
		}else{
			String jsonStr = loanBasicDataConsumerApi.getBasicDatas();
			MarvelsResultDTO result = JSON.parseObject(jsonStr,MarvelsResultDTO.class);
			return result;
		}
	}
	
	
	
	/**
	 * 获取上传附件下拉框值
	 */
	@Override
	public MarvelsResultDTO getUploadAttamentTypes(String loanId) throws MarvelsBusinessException {
//		boolean callFlag = false;
//		List<String> params = new ArrayList<String>();
//		params.add(MarvelsConstant.PURPOSE_LIST);
//		params.add(MarvelsConstant.PAYMENT_MODE_LIST);
//		params.add(MarvelsConstant.LIFE_INSURANCE_TYPE_LIST);
//		params.add(MarvelsConstant.INSURANCE_TYPE_LIST);
//		params.add(MarvelsConstant.INSURANCE_STATUS_LIST);
//		params.add(MarvelsConstant.INSURANCE_COMPANY_LIST);
//		Map<String,List<BasicDataDTO>> map = getCacheBasicDatas(params);
//		if(map == null || map.size() != params.size()){
//			callFlag = true;
//		}
		
		LaAttachAtmeTypeViewDTO attachmentTypeDto = new LaAttachAtmeTypeViewDTO();
		attachmentTypeDto.setViewKey(CaseNodeConstant.WOCHECKINGBEFORE.getCode());
		List<LaAttachAtmeTypeViewDTO> attachMents = applyProvideConsumerApi.getAttachAtmeTypeInfo(attachmentTypeDto);
//		Map<Integer, List<OpinionTypeDTO>> opinionTypes = opinionTypeService.getOpinionTypes(CaseNodeConstant.WOCHECKINGBEFORE.getCode());
//		if(!org.springframework.util.CollectionUtils.isEmpty(opinionTypes)){
//			dataMap.put("opinionTypes", opinionTypes);
//		}
//		dataMap.put("mediaList",creditReportService.getUserMediaByLoanId(loanId));
//		if(!callFlag){
//			dataMap.put("data", map);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), attachMents);
//		}else{
//			String jsonStr = loanBasicDataConsumerApi.getBasicDatas();
//			MarvelsResultDTO result = JSON.parseObject(jsonStr,MarvelsResultDTO.class);
//			dataMap.put("data", result);
//			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), dataMap);
//		}
	}
	
	
	
	
	/**
	 * 从redis中获取基表数据
	 * @param params
	 * @return
	 */
	private Map<String,List<BasicDataDTO>> getCacheBasicDatas(List<String> params){
		Map<String,List<BasicDataDTO>> map = null;
		if(CollectionUtils.isNotEmpty(params)){
			map = new HashMap<String,List<BasicDataDTO>>();
			for(String param : params){
				List<BasicDataDTO> list = getCacheList(param);
				if(CollectionUtils.isNotEmpty(list)){
					map.put(param, list);
				}else{
					break;
				}
			}
		}
		return map;
	}
	
	private List<BasicDataDTO> getCacheList(String key){
		List<BasicDataDTO> list = null;
		Object o = CacheUtils.getCacheObject(key);
		if(o != null){
			list = (List<BasicDataDTO>)o;
		}
		return list;
	}

	@Override
	public McamLoanApplyInfoDTO saveLoanInfo(McamLoanApplyInfoDTO loanInfo) throws MarvelsBusinessException {
		if(loanInfo == null){
			throw new MarvelsBusinessException("入参为空");
		}
		if(StringUtils.isEmpty(loanInfo.getLoanId())){
			throw new MarvelsBusinessException("loanId为空");
		}
		loanInfo.setUpdatedBy(loanInfo.obtainLoginUserName());
		taskProcessDao.updateLoanInfo(loanInfo);
		if(loanInfo.getInsurancePolicy()!=null){//更新保单
			loanInfo.getInsurancePolicy().setLoanId(loanInfo.getLoanId());
			loanInfo.getInsurancePolicy().setUpdatedBy(loanInfo.obtainLoginUserName());
			taskProcessDao.updateInsurancePolicy(loanInfo.getInsurancePolicy());
			if(loanInfo.getInsuranceCheck()!=null){
				InsuranceCheckDTO  checkDto = taskProcessDao.selectInsuranceCheckInfo(loanInfo.getLoanId());
				loanInfo.getInsuranceCheck().setLoanId(loanInfo.getLoanId());
				loanInfo.getInsuranceCheck().setUpdatedBy(loanInfo.obtainLoginUserName());
				if(checkDto==null){//新增保单核录
					loanInfo.getInsuranceCheck().setInsuranceId(loanInfo.getInsurancePolicy().getInsuranceId());
					loanInfo.getInsuranceCheck().setCreatedBy(loanInfo.obtainLoginUserName());
					taskProcessDao.saveInsuranceCheck(loanInfo.getInsuranceCheck());
				}else{//更新保单核录
					taskProcessDao.updateInsuranceCheck(loanInfo.getInsuranceCheck());
				}
			}
		}
		saveEstateInfo(loanInfo.getEstateList(),loanInfo.getLoanId());
		loanInfo.setEstateList(taskProcessDao.selectEstateList(loanInfo.getLoanId()));
		return loanInfo;
	}
	
	/**
	 * 保存房产信息
	 * @param estateList
	 * @param loanId
	 * @throws MarvelsBusinessException
	 */
	private void saveEstateInfo(List<EstateInfoDTO> estateList,String loanId) throws MarvelsBusinessException{
		if(CollectionUtils.isNotEmpty(estateList)){
			List<EstateInfoDTO> listToSave = new ArrayList<EstateInfoDTO>();
			List<EstateInfoDTO> listToUpdate = new ArrayList<EstateInfoDTO>();
			for(EstateInfoDTO estate : estateList){
				if(StringUtils.isEmpty(estate.getId())){
					estate.setCreatedBy(estate.obtainLoginUserName());
					estate.setUpdatedBy(estate.obtainLoginUserName());
					estate.setLoanId(loanId);
					listToSave.add(estate);
				}else{
					estate.setUpdatedBy(estate.obtainLoginUserName());
					estate.setLoanId(loanId);
					listToUpdate.add(estate);
				}
			}
			if(CollectionUtils.isNotEmpty(listToSave)){
				taskProcessDao.insertEstate(listToSave);
			}
			if(CollectionUtils.isNotEmpty(listToUpdate)){
				taskProcessDao.updateEstate(listToUpdate);
			}
		}
	}

	@Override
	public Integer deleteEstateInfo(EstateInfoDTO estateInfo) throws MarvelsBusinessException {
		if(estateInfo == null || StringUtils.isEmpty(estateInfo.getId())){
			throw new MarvelsBusinessException("入参为空");
		}
		estateInfo.setUpdatedBy(estateInfo.obtainLoginUserName());
		Integer n = taskProcessDao.deleteEstateInfo(estateInfo);
		return n;
	}

	@Override
	public MarvelsResultDTO getCustomerBasicDatas() throws MarvelsBusinessException {
		boolean callFlag = false;
		List<String> params = new ArrayList<String>();
		params.add(MarvelsConstant.EMPLOY_TYPE_LIST);
		params.add(MarvelsConstant.MARITAL_STATUS_LIST);
		params.add(MarvelsConstant.EDUCATION_LEVEL_LIST);
		params.add(MarvelsConstant.LIVE_TYPE_LIST);
//		params.add(MarvelsConstant.PROVINCE_LIST);
//		params.add(MarvelsConstant.CITY_LIST);
//		params.add(MarvelsConstant.REGION_LIST);
		params.add(MarvelsConstant.COMPANY_TYPE_LIST);
		params.add(MarvelsConstant.WORKTIME_TYPE_LIST);
		params.add(MarvelsConstant.INCOME_TYPE_LIST);
		params.add(MarvelsConstant.RELATION_LIST);
//		params.add(MarvelsConstant.RELATION_OTHER_LIST);
		params.add(MarvelsConstant.PHONE_CHK_RESULT_LIST);
		params.add(MarvelsConstant.ENTERPRISE_SCALE_TYPE_LIST);
		params.add(MarvelsConstant.THREE_CAREER_TYPE_LIST);
		params.add(MarvelsConstant.TWO_CAREER_TYPE_LIST);
		Map<String,List<BasicDataDTO>> map = getCacheBasicDatas(params);
		if(map == null || map.size() != params.size()){
			callFlag = true;
		}
		if(!callFlag){
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), map);
		}else{
			MarvelsResultDTO result = loanBasicDataConsumerApi.getCustomerBasicDatas();
			return result;
		}
	}

	@Override
	public McamLoanApplyInfoDTO getCustomerDetail(String loanId) throws MarvelsBusinessException {
		McamLoanApplyInfoDTO loanApplyInfo = selectLoanApplyInfo(loanId);
		String reLoanId =  thirdCreditReportService.getThirdLoanId(loanId);
		// 紧急联系人
		List<MclaLoanApplyLinkmanDTO> reloanList = mclaLinkmanMobileApi.selectByLoanId(reLoanId);
		loanApplyInfo.setReloanList(reloanList);
		// 联系人信息
		/*List<LoanApplyContactInfoDTO> contacts = taskProcessDao.selectContacts(loanId);
		loanApplyInfo.setContacts(contacts);*/
		// 联系人验证结果
//		List<LoanContactCheckDTO> contactChks = taskProcessDao.selectContactChecks(loanId);
//		loanApplyInfo.setContactChks(contactChks);
		// 开心购信息
		List<LoanFeelInfoDTO> feelChks = taskProcessDao.selectFeelChecks(loanId);
		loanApplyInfo.setFeelChks(feelChks);
		// 电核录入
		List<PhoneCheckDTO> phoneChks = taskProcessDao.selectPhoneChecks(loanId);
		loanApplyInfo.setPhoneChks(phoneChks);
		return loanApplyInfo;
	}

	@Override
	public McamLoanApplyInfoDTO saveCustomerInfo(McamLoanApplyInfoDTO loanApplyInfo) throws MarvelsBusinessException {
		if(loanApplyInfo == null){
			throw new MarvelsBusinessException("入参为空");
		}
		if(StringUtils.isEmpty(loanApplyInfo.getLoanId())){
			throw new MarvelsBusinessException("loanId为空");
		}
		loanApplyInfo.setUpdatedBy(loanApplyInfo.obtainLoginUserName());
		taskProcessDao.updateCustomerInfo(loanApplyInfo);
		saveContacts(loanApplyInfo);
//		saveContactChkResults(loanApplyInfo);
		savePhoneCheckList(loanApplyInfo);
		loanApplyInfo.setContacts(taskProcessDao.selectContacts(loanApplyInfo.getLoanId()));
//		loanApplyInfo.setContactChks(taskProcessDao.selectContactChecks(loanApplyInfo.getLoanId()));
		loanApplyInfo.setPhoneChks(taskProcessDao.selectPhoneChecks(loanApplyInfo.getLoanId()));
		return loanApplyInfo;
	}
	
	/**
	 * 保存联系人
	 * @param loanApplyInfo
	 * @throws MarvelsBusinessException
	 */
	private void saveContacts(McamLoanApplyInfoDTO loanApplyInfo)throws MarvelsBusinessException{
		String loanId = loanApplyInfo.getLoanId();
		List<LoanApplyContactInfoDTO> contacts = loanApplyInfo.getContacts();
		if(CollectionUtils.isNotEmpty(contacts)){
			List<LoanApplyContactInfoDTO> listToSave = new ArrayList<LoanApplyContactInfoDTO>();
			List<LoanApplyContactInfoDTO> listToUpdate = new ArrayList<LoanApplyContactInfoDTO>();
			for(LoanApplyContactInfoDTO contact : contacts){
				contact.setUpdatedBy(contact.obtainLoginUserName());
				contact.setLoanId(loanId);
				if(contact.getId() == null || contact.getId() == 0){
					contact.setCreatedBy(contact.obtainLoginUserName());
					listToSave.add(contact);
				}else{
					listToUpdate.add(contact);
				}
			}
			if(CollectionUtils.isNotEmpty(listToSave)){
				for(LoanApplyContactInfoDTO c : listToSave){//每新增一条联系人信息，自动新增一条联系人验证信息
					c.setApproveStatus("Y");
					taskProcessDao.insertContact(c);
//					LoanContactCheckDTO contactChk = new LoanContactCheckDTO();
//					contactChk.setLoanId(loanId);
//					contactChk.setLoanApplyContactId(c.getId());
//					contactChk.setApproveStatus("Y");
//					contactChk.setContactName(c.getContactName());
//					contactChk.setCreatedBy(c.obtainLoginUserName());
//					contactChk.setUpdatedBy(c.obtainLoginUserName());
//					taskProcessDao.insertContactChk(contactChk);
				}
			}
			if(CollectionUtils.isNotEmpty(listToUpdate)){
				taskProcessDao.updateContactList(listToUpdate);
			}
		}
	}
	
	/**
	 * 保存联系人验证结果
	 * 联系人验证结果自动会新增一条‘本人’的验证记录
	 * @param loanApplyInfo
	 * @throws MarvelsBusinessException
	 */
	private void saveContactChkResults(McamLoanApplyInfoDTO loanApplyInfo)throws MarvelsBusinessException{
		List<LoanContactCheckDTO> list = loanApplyInfo.getContactChks();
		if(CollectionUtils.isNotEmpty(list)){
			Integer n = null;
			for(int i=0;i<list.size();i++){
				LoanContactCheckDTO contactChk = list.get(i);
				contactChk.setUpdatedBy(contactChk.obtainLoginUserName());
				//‘本人’单独处理，
				if(-1 == contactChk.getLoanApplyContactId() && (contactChk.getId()==null || contactChk.getId()==0)){
					contactChk.setLoanId(loanApplyInfo.getLoanId());
					contactChk.setApproveStatus("Y");
					contactChk.setCreatedBy(contactChk.obtainLoginUserName());
					contactChk.setUpdatedBy(contactChk.obtainLoginUserName());
					taskProcessDao.insertContactChk(contactChk);
					n = i;
				}
			}
			if(n != null){
				list.remove(n);
			}
			taskProcessDao.updateContactChkList(list);
		}
	}
	
	/**
	 * 保存电核记录
	 * @param loanApplyInfo
	 * @throws MarvelsBusinessException
	 */
	private void savePhoneCheckList(McamLoanApplyInfoDTO loanApplyInfo) throws MarvelsBusinessException{
		List<PhoneCheckDTO> phoneChks = loanApplyInfo.getPhoneChks();
		if(CollectionUtils.isNotEmpty(phoneChks)){
			String loanId = loanApplyInfo.getLoanId();
			List<PhoneCheckDTO> listToSave = new ArrayList<PhoneCheckDTO>();
			List<PhoneCheckDTO> listToUpdate = new ArrayList<PhoneCheckDTO>();
			for(PhoneCheckDTO phoneChk : phoneChks){
				phoneChk.setUpdatedBy(phoneChk.obtainLoginUserName());
				phoneChk.setLoanId(loanId);
				if(phoneChk.getId()==null || phoneChk.getId()==0){
					phoneChk.setCreatedBy(phoneChk.obtainLoginUserName());
					listToSave.add(phoneChk);
				}else{
					listToUpdate.add(phoneChk);
				}
			}
			if(CollectionUtils.isNotEmpty(listToSave)){
				taskProcessDao.insertPhoneChkList(listToSave);
			}
			if(CollectionUtils.isNotEmpty(listToUpdate)){
				taskProcessDao.updatePhoneChkList(listToUpdate);
			}
		}
	}

	@Override
	public SysUserDTO getLoginUserInfo() throws MarvelsBusinessException {
		UserDTO user = CacheUtils.getCacheUser();
		SysUserDTO u = sysUserApi.querySysUser(user.getUserId());
		return u;
	}

	@Override
	public Page<McamLoanApplyInfoDTO> getHistoryLoanInfoPage(McamLoanApplyInfoDTO loanInfo,Integer pageNo,Integer pageSize)throws MarvelsBusinessException {
		if(pageNo <= 0){
			pageNo = 1;
		}
		if(pageSize <=0){
			pageSize = 10;
		}
		PageHelper.startPage(pageNo, pageSize);
		Page<McamLoanApplyInfoDTO> pageList = taskProcessDao.selectHistoryLoanInfoPage(loanInfo);
		//转换状态
		StateDetailedDTO dto = new StateDetailedDTO();
		List<StateDetailedDTO> stateList = consumerLoanApplyApi.queryStateDetailed(dto);
		for (McamLoanApplyInfoDTO mcamLoanApplyInfoDTO : pageList) {
			if(mcamLoanApplyInfoDTO.getStatus() != null){
				for (StateDetailedDTO stateDetailedDTO : stateList) {
					if(mcamLoanApplyInfoDTO.getStatus().equals(stateDetailedDTO.getStateId())){
						mcamLoanApplyInfoDTO.setStatus(stateDetailedDTO.getStateExplain());
						break;
					}
				}
			}
		}
		return pageList;
	}

	@Override
	public Page<TrickCheckInfoDTO> getTrickCheckInfoPage(McamLoanApplyInfoDTO loanInfo, Integer pageNo, Integer pageSize)
			throws MarvelsBusinessException {
		if(pageNo <= 0){
			pageNo = 1;
		}
		if(pageSize <=0){
			pageSize = 5;
		}
		PageHelper.startPage(pageNo, pageSize);
		Page<TrickCheckInfoDTO> pageList = taskProcessDao.selectTrickCheckInfoPage(loanInfo);
		return pageList;
	}

	@Override
	public Page<RiskCheckInfoDTO> getRiskCheckInfoPage(McamLoanApplyInfoDTO loanInfo, Integer pageNo, Integer pageSize)
			throws MarvelsBusinessException {
		if(pageNo <= 0){
			pageNo = 1;
		}
		if(pageSize <=0){
			pageSize = 5;
		}
		PageHelper.startPage(pageNo, pageSize);
		Page<RiskCheckInfoDTO> pageList = taskProcessDao.selectRiskCheckInfoPage(loanInfo);
		return pageList;
	}

	@Override
	public void updateTrickAndRiskCheckData(String loanId) throws MarvelsBusinessException {
		if(StringUtils.isEmpty(loanId)){
			throw new MarvelsBusinessException("loanId 为空");
		}
		McamLoanApplyInfoDTO loanApplyInfo = taskProcessDao.selectLoanApplyInfo(loanId);
		if(loanApplyInfo == null){
			throw new MarvelsBusinessException("查无此信息, loanId="+loanId);
		}
		//删除现有检测结果
		taskProcessDao.deleteTrickCheckDataByLoanId(loanId);
		taskProcessDao.deleteRiskCheckDataByLoanId(loanId);
		String custCardNo = loanApplyInfo.getCustCardNo();//客户身份证
		String custCardAddr = loanApplyInfo.getCustCardAddress();//客户身份证的居住地址
		String custName = loanApplyInfo.getCustName();//客户姓名
		String mobileNo = loanApplyInfo.getMobileNo();//客户手机
		String companyTel = loanApplyInfo.getCompanyTel();//客户公司电话
		String companyName = loanApplyInfo.getCompanyName();//公司名称
		String companyAddr = loanApplyInfo.getCompanyAddress();//公司地址
		List<LoanApplyContactInfoDTO> contacts = taskProcessDao.selectContacts(loanId);
		//获取亲属联系人
		List<LoanApplyContactInfoDTO> relatives = new ArrayList<LoanApplyContactInfoDTO>();
		//获取其它联系人
		List<LoanApplyContactInfoDTO> others = new ArrayList<LoanApplyContactInfoDTO>();
		if(CollectionUtils.isNotEmpty(contacts)){
			for(LoanApplyContactInfoDTO contact : contacts){
				if(contact.getContactType() == 0){
					relatives.add(contact);
				}else if(contact.getContactType() == 1){
					others.add(contact);
				}
			}
		}
		//查询欺诈记录，添加到欺诈检核过滤结果表
		if(StringUtils.isNotEmpty(custCardNo)){//身份证
			saveFakeData(loanId,"cust_card_no",custCardNo,"证件号码","证件号码");
		}
		if(StringUtils.isNotEmpty(mobileNo)){//手机
			saveFakeData(loanId,"mobile_no",mobileNo,"手机号码","手机号码");
			saveFakeData(loanId,"relative_contact_mobile_no",mobileNo,"手机号码","直系联系人手机");
			saveFakeData(loanId,"other_contact_mobile_no",mobileNo,"手机号码","联系人手机");
		}
		if(CollectionUtils.isNotEmpty(relatives)){//亲属联系人
			for(LoanApplyContactInfoDTO relative : relatives){
				saveFakeData(loanId,"mobile_no",relative.getContactMobile(),"直系联系人手机","手机号码");
				saveFakeData(loanId,"relative_contact_mobile_no",relative.getContactMobile(),"直系联系人手机","直系联系人手机");
				saveFakeData(loanId,"other_contact_mobile_no",relative.getContactMobile(),"直系联系人手机","联系人手机");
			}
		}
		if(CollectionUtils.isNotEmpty(others)){//其他联系人
			for(LoanApplyContactInfoDTO other : others){
				saveFakeData(loanId,"mobile_no",other.getContactMobile(),"联系人手机","手机号码");
				saveFakeData(loanId,"relative_contact_mobile_no",other.getContactMobile(),"联系人手机","直系联系人手机");
				saveFakeData(loanId,"other_contact_mobile_no",other.getContactMobile(),"联系人手机","联系人手机");
			}
		}
		if(StringUtils.isNotEmpty(companyTel)){//公司电话
			saveFakeData(loanId,"company_tel",companyTel,"单位电话","单位电话");
		}
		
		//单位名称、单位地址、居住地址的数据不从数据库取，从SOLR中取
		SolrUtils.getInstance(solrUrl);
		String companyNameJson = SolrUtils.querySimpleRtnJson("company_name", companyName, "company_name");
        String companyAddressJson = SolrUtils.querySimpleRtnJson("company_address", companyAddr, "company_address");
        String lifeAddressJson = SolrUtils.querySimpleRtnJson("life_address", custCardAddr, "life_address");
        List<Map> companyNameList = JSON.parseArray(companyNameJson, Map.class);
        List<Map> companyAddressList = JSON.parseArray(companyAddressJson, Map.class);
		List<Map> lifeAddressList = JSON.parseArray(lifeAddressJson, Map.class);
		// 单位名称.单位名称
        if (StringUtils.isNotEmpty(companyName)) {
        	List<TrickCheckInfoDTO> list = new ArrayList<TrickCheckInfoDTO>();
            for (Map<String, Object> map : companyNameList) {
                String companyName1 = (String) map.get("company_name");
                String id = (String) map.get("id");
                if (StringUtils.isNotEmpty(companyName1) && StringUtils.isNotEmpty(id) && !"null".equals(id)) {
                    if(companyName.equals(companyName1)){
                    	TrickCheckInfoDTO t = setData2TrickCheckInfo(Long.valueOf(id),
                    			loanId,"单位名称","单位名称",companyName1);
                        list.add(t);
                      }
                }
            }
            if(CollectionUtils.isNotEmpty(list)){
            	taskProcessDao.insertTrickCheckList(list);
            }
        }
        McsmSystemParam param=new McsmSystemParam();
		param.setParamNames(new String[]{"CHECK_ADDRESS_WEIGHT"});
		List<McsmSystemParam> paramsList = consumerSystemApi.paramList(param);
        if(CollectionUtils.isEmpty(paramsList) || StringUtils.isEmpty(paramsList.get(0).getParamValue())){
        	throw new MarvelsBusinessException("系统地址检测权重值CHECK_ADDRESS_WEIGHT未配置");
        }
        //系统配置的地址检测权重值
        BigDecimal sysWeights = BigDecimal.valueOf(Double.valueOf(paramsList.get(0).getParamValue()));
        // 单位地址.单位地址
        if (StringUtils.isNotEmpty(companyAddr)) {
        	List<TrickCheckInfoDTO> list = new ArrayList<TrickCheckInfoDTO>();
            for (Map<String, Object> map : companyAddressList) {
                String companyAddress = (String) map.get("company_address");
                String id = (String) map.get("id");
                if (StringUtils.isNotEmpty(companyAddress) && StringUtils.isNotEmpty(id) && !"null".equals(id)) {
                	BigDecimal addrWeights = taskProcessDao.calculateAddrWeights(companyAddr,companyAddress);
                    if (addrWeights.compareTo(sysWeights)>0) {
                    	TrickCheckInfoDTO t = setData2TrickCheckInfo (Long.valueOf(id),
                    			loanId,"单位地址","单位地址",companyAddress);
                        list.add(t);
                    }
                }
            }
            if(CollectionUtils.isNotEmpty(list)){
            	taskProcessDao.insertTrickCheckList(list);
            }
        }
        // 单位地址.居住地址
        if (StringUtils.isNotEmpty(companyAddr)) {
        	List<TrickCheckInfoDTO> list = new ArrayList<TrickCheckInfoDTO>();
            for (Map<String, Object> map : lifeAddressList) {
                String lifeAddress = (String) map.get("life_address");
                String id = (String) map.get("id");
                if (StringUtils.isNotEmpty(lifeAddress) && StringUtils.isNotEmpty(id) && !"null".equals(id)) {
                	BigDecimal addrWeights = taskProcessDao.calculateAddrWeights(companyAddr,lifeAddress);
                    if (addrWeights.compareTo(sysWeights)>0) {
                        TrickCheckInfoDTO t = setData2TrickCheckInfo (Long.valueOf(id),
                    			loanId,"单位地址","居住地址",lifeAddress);
                        list.add(t);
                    }
                }
            }
            if(CollectionUtils.isNotEmpty(list)){
            	taskProcessDao.insertTrickCheckList(list);
            }
        }
        // 居住地址.居住地址
        if (StringUtils.isNotEmpty(custCardAddr)) {
        	List<TrickCheckInfoDTO> list = new ArrayList<TrickCheckInfoDTO>();
            for (Map<String, Object> map : lifeAddressList) {
                String lifeAddress = (String) map.get("life_address");
                String id = (String) map.get("id");
                if (StringUtils.isNotEmpty(lifeAddress) && StringUtils.isNotEmpty(id) && !"null".equals(id)) {
                	BigDecimal addrWeights = taskProcessDao.calculateAddrWeights(custCardAddr,lifeAddress);
                    if (addrWeights.compareTo(sysWeights) >0) {
                        TrickCheckInfoDTO t = setData2TrickCheckInfo (Long.valueOf(id),
                    			loanId,"居住地址","居住地址",lifeAddress);
                        list.add(t);
                    }
                }
            }
            if(CollectionUtils.isNotEmpty(list)){
            	taskProcessDao.insertTrickCheckList(list);
            }
        }
        // 居住地址.单位地址
        if (StringUtils.isNotEmpty(custCardAddr)) {
        	List<TrickCheckInfoDTO> list = new ArrayList<TrickCheckInfoDTO>();
            for (Map<String, Object> map : companyAddressList) {
                String companyAddress = (String) map.get("company_address");
                String id = (String) map.get("id");
                if (StringUtils.isNotEmpty(companyAddress) && StringUtils.isNotEmpty(id) && !"null".equals(id)) {
                	BigDecimal addrWeights = taskProcessDao.calculateAddrWeights(custCardAddr,companyAddress);
                    if (addrWeights.compareTo(sysWeights) >0) {
                        TrickCheckInfoDTO t = setData2TrickCheckInfo (Long.valueOf(id),
                    			loanId,"居住地址","单位地址",companyAddress);
                        list.add(t);
                    }
                }
            }
            if(CollectionUtils.isNotEmpty(list)){
            	taskProcessDao.insertTrickCheckList(list);
            }
        }
        
        //查询历史贷款产品信息，添加到风险检核过滤结果表
        //存量信息.证件号码+客户姓名
        //查询条件
        McamLoanApplyInfoDTO loanInfo = new McamLoanApplyInfoDTO();
        loanInfo.setLoanId(loanId);
        loanInfo.setCustCardNo(custCardNo);
        loanInfo.setCustName(custName);
        //查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("'证件号码+客户姓名' as applyColumn");
        columns.add("loan_id as matchApplyNo");
        columns.add("'存量申请' as matchSource");
        columns.add("'证件号码+客户姓名' as columnName");
        columns.add("'"+custCardNo+"+"+custName+"' as matchText");
        columns.add("'RA01-证件号码相同，客户姓名不同' as matchCode");
        columns.add("'"+loanId+"' as loanId");
        saveRiskCheckInfoData(columns,loanInfo,1);
        //存量信息.手机号码:手机号码
        loanInfo = new McamLoanApplyInfoDTO();
        loanInfo.setLoanId(loanId);
        loanInfo.setCustCardNo(custCardNo);
        loanInfo.setMobileNo(mobileNo);
        columns.clear();
        columns.add("'手机号码' as applyColumn");
        columns.add("loan_id as matchApplyNo");
        columns.add("'存量申请' as matchSource");
        columns.add("'手机号码' as columnName");
        columns.add("'"+mobileNo+"' as matchText");
        columns.add("'RA02-匹配内容相同,证件号码不同' as matchCode");
        columns.add("'"+loanId+"' as loanId");
        saveRiskCheckInfoData(columns,loanInfo,2);
        //存量信息.手机号码：直系联系人手机
        columns.clear();
        columns.add("'手机号码' as applyColumn");
        columns.add("loan_id as matchApplyNo");
        columns.add("'存量申请' as matchSource");
        columns.add("'直系联系人手机' as columnName");
        columns.add("'"+mobileNo+"' as matchText");
        columns.add("'RA03-匹配内容相同,证件号码不同' as matchCode");
        columns.add("'"+loanId+"' as loanId");
        saveRiskCheckInfoData(columns,loanInfo,3);
        //存量信息.手机号码：联系人手机
        columns.clear();
        columns.add("'手机号码' as applyColumn");
        columns.add("loan_id as matchApplyNo");
        columns.add("'存量申请' as matchSource");
        columns.add("'联系人手机' as columnName");
        columns.add("'"+mobileNo+"' as matchText");
        columns.add("'RA04-匹配内容相同,证件号码不同' as matchCode");
        columns.add("'"+loanId+"' as loanId");
        saveRiskCheckInfoData(columns,loanInfo,4);
        //存量信息.直系联系人手机号码：手机号码
        if(CollectionUtils.isNotEmpty(relatives)){
        	for(LoanApplyContactInfoDTO c : relatives){
        		columns.clear();
                columns.add("'直系联系人手机' as applyColumn");
                columns.add("loan_id as matchApplyNo");
                columns.add("'存量申请' as matchSource");
                columns.add("'手机号码' as columnName");
                columns.add("'"+c.getContactMobile()+"' as matchText");
                columns.add("'RA05-匹配内容相同,证件号码不同' as matchCode");
                columns.add("'"+loanId+"' as loanId");
                loanInfo = new McamLoanApplyInfoDTO();
                loanInfo.setLoanId(loanId);
                loanInfo.setCustCardNo(custCardNo);
                loanInfo.setMobileNo(c.getContactMobile());
                saveRiskCheckInfoData(columns,loanInfo,5);
        	}
        	
        	//存量信息.直系联系人手机号码：直系联系人手机
        	for(LoanApplyContactInfoDTO c : relatives){
        		columns.clear();
                columns.add("'直系联系人手机' as applyColumn");
                columns.add("loan_id as matchApplyNo");
                columns.add("'存量申请' as matchSource");
                columns.add("'直系联系人手机' as columnName");
                columns.add("'"+c.getContactMobile()+"' as matchText");
                columns.add("'RA06-匹配内容相同,证件号码不同' as matchCode");
                columns.add("'"+loanId+"' as loanId");
                loanInfo = new McamLoanApplyInfoDTO();
                loanInfo.setLoanId(loanId);
                loanInfo.setCustCardNo(custCardNo);
                loanInfo.setMobileNo(c.getContactMobile());
                saveRiskCheckInfoData(columns,loanInfo,6);
        	}
        	//存量信息.直系联系人手机号码：联系人手机
        	for(LoanApplyContactInfoDTO c : relatives){
        		columns.clear();
                columns.add("'直系联系人手机' as applyColumn");
                columns.add("loan_id as matchApplyNo");
                columns.add("'存量申请' as matchSource");
                columns.add("'联系人手机' as columnName");
                columns.add("'"+c.getContactMobile()+"' as matchText");
                columns.add("'RA07-匹配内容相同,证件号码不同' as matchCode");
                columns.add("'"+loanId+"' as loanId");
                loanInfo = new McamLoanApplyInfoDTO();
                loanInfo.setLoanId(loanId);
                loanInfo.setCustCardNo(custCardNo);
                loanInfo.setMobileNo(c.getContactMobile());
                saveRiskCheckInfoData(columns,loanInfo,7);
        	}
        }
        //存量信息.联系人手机：手机号码
        if(CollectionUtils.isNotEmpty(others)){
        	for(LoanApplyContactInfoDTO c : others){
        		columns.clear();
                columns.add("'联系人手机' as applyColumn");
                columns.add("loan_id as matchApplyNo");
                columns.add("'存量申请' as matchSource");
                columns.add("'手机号码' as columnName");
                columns.add("'"+c.getContactMobile()+"' as matchText");
                columns.add("'RA08-匹配内容相同,证件号码不同' as matchCode");
                columns.add("'"+loanId+"' as loanId");
                loanInfo = new McamLoanApplyInfoDTO();
                loanInfo.setLoanId(loanId);
                loanInfo.setCustCardNo(custCardNo);
                loanInfo.setMobileNo(c.getContactMobile());
                saveRiskCheckInfoData(columns,loanInfo,8);
        	}
        	//存量信息.联系人手机：直系联系人手机
        	for(LoanApplyContactInfoDTO c : others){
        		columns.clear();
                columns.add("'联系人手机' as applyColumn");
                columns.add("loan_id as matchApplyNo");
                columns.add("'存量申请' as matchSource");
                columns.add("'直系联系人手机' as columnName");
                columns.add("'"+c.getContactMobile()+"' as matchText");
                columns.add("'RA09-匹配内容相同,证件号码不同' as matchCode");
                columns.add("'"+loanId+"' as loanId");
                loanInfo = new McamLoanApplyInfoDTO();
                loanInfo.setLoanId(loanId);
                loanInfo.setCustCardNo(custCardNo);
                loanInfo.setMobileNo(c.getContactMobile());
                saveRiskCheckInfoData(columns,loanInfo,9);
        	}
        	//存量信息.联系人手机：联系人手机
        	for(LoanApplyContactInfoDTO c : others){
        		columns.clear();
                columns.add("'联系人手机' as applyColumn");
                columns.add("loan_id as matchApplyNo");
                columns.add("'存量申请' as matchSource");
                columns.add("'联系人手机' as columnName");
                columns.add("'"+c.getContactMobile()+"' as matchText");
                columns.add("'RA10-匹配内容相同,证件号码不同' as matchCode");
                columns.add("'"+loanId+"' as loanId");
                loanInfo = new McamLoanApplyInfoDTO();
                loanInfo.setLoanId(loanId);
                loanInfo.setCustCardNo(custCardNo);
                loanInfo.setMobileNo(c.getContactMobile());
                saveRiskCheckInfoData(columns,loanInfo,10);
        	}
        }
        //存量信息.单位电话：单位电话
        columns.clear();
        columns.add("'单位电话' as applyColumn");
        columns.add("loan_id as matchApplyNo");
        columns.add("'存量申请' as matchSource");
        columns.add("'单位电话' as columnName");
        columns.add("'"+companyTel+"' as matchText");
        columns.add("'RA11-匹配内容相同,证件号码不同' as matchCode");
        columns.add("'"+loanId+"' as loanId");
        loanInfo = new McamLoanApplyInfoDTO();
        loanInfo.setLoanId(loanId);
        loanInfo.setCustCardNo(custCardNo);
        loanInfo.setCompanyTel(companyTel);
        saveRiskCheckInfoData(columns,loanInfo,11);
        //存量信息.单位名称：单位名称
        columns.clear();
        columns.add("'单位名称' as applyColumn");
        columns.add("loan_id as matchApplyNo");
        columns.add("'存量申请' as matchSource");
        columns.add("'单位名称' as columnName");
        columns.add("'"+companyName+"' as matchText");
        columns.add("'RA12-匹配内容相同,证件号码不同' as matchCode");
        columns.add("'"+loanId+"' as loanId");
        loanInfo = new McamLoanApplyInfoDTO();
        loanInfo.setLoanId(loanId);
        loanInfo.setCustCardNo(custCardNo);
        loanInfo.setCompanyName(companyName);
        saveRiskCheckInfoData(columns,loanInfo,12);
	}
	
	/**
	 * 查询欺诈数据，并保存到欺诈检核结果
	 * @param loanId
	 * @param column
	 * @param columnValue
	 * @param applyColumnName
	 * @param fakeColumnName
	 * @throws MarvelsBusinessException
	 */
	private void saveFakeData(String loanId,String column,String columnValue,String applyColumnName,String fakeColumnName) throws MarvelsBusinessException{
		List<FakeInfoDTO> data = taskProcessDao.selectFakeInfoByCondition(column, columnValue);
		if(CollectionUtils.isNotEmpty(data)){
			List<TrickCheckInfoDTO> list = new ArrayList<TrickCheckInfoDTO>();
			for(FakeInfoDTO dto : data){
				TrickCheckInfoDTO t = setData2TrickCheckInfo (dto.getId(),loanId,applyColumnName,fakeColumnName,columnValue);
                list.add(t);
			}
			taskProcessDao.insertTrickCheckList(list);
		}
	}
	
	/**
	 * 数据装载到欺诈检核结果dto，并返回TrickCheckInfoDTO
	 * @param fakeId
	 * @param loanId
	 * @param applyColumn
	 * @param fakeColumn
	 * @param matchField
	 * @return
	 * @throws MarvelsBusinessException
	 */
	private TrickCheckInfoDTO setData2TrickCheckInfo (Long fakeId,String loanId,String applyColumn,String fakeColumn,String matchField) throws MarvelsBusinessException{
		TrickCheckInfoDTO t = new TrickCheckInfoDTO();
        t.setFakeId(fakeId);
        t.setLoanId(loanId);
        t.setApplyColumn(applyColumn);
        t.setFakeColumn(fakeColumn);
        t.setMatchField(matchField);
        t.setCreatedBy(t.obtainLoginUserName());
        t.setUpdatedBy(t.obtainLoginUserName());
        return t;
	}
	
	/**
	 * 查询风险数据，并保存到风险检核结果
	 * @param columns
	 * @param loanInfo
	 * @param conditionType
	 * @throws MarvelsBusinessException
	 */
	private void saveRiskCheckInfoData(List<String> columns,McamLoanApplyInfoDTO loanInfo,Integer conditionType) throws MarvelsBusinessException{
		List<RiskCheckInfoDTO> riskList = taskProcessDao.selectRiskCheckInfoByHistoryLoanInfo(columns,loanInfo,conditionType);
        if(CollectionUtils.isNotEmpty(riskList)){
        	for(RiskCheckInfoDTO r : riskList){
        		r.setCreatedBy(r.obtainLoginUserName());
        		r.setUpdatedBy(r.obtainLoginUserName());
        	}
        	taskProcessDao.insertRiskCheckList(riskList);
        }
	}

	@Override
	public LoanApplyCaseDTO getLoanApplyCaseLogs(String loanId) throws MarvelsBusinessException {
		if(StringUtils.isEmpty(loanId)){
			throw new MarvelsBusinessException("loanId 为空");
		}
		LoanApplyCaseDTO loanApplyCase = taskProcessDao.selectCaseLogs(loanId);
		return loanApplyCase;
	}

	@Override
	public List<OpinionTypeDTO> getReturnReasonList() throws MarvelsBusinessException {
		Map<Integer, List<OpinionTypeDTO>> opinionTypes = opinionTypeService.getOpinionTypes(CaseNodeConstant.WOCHECKINGBEFORE.getCode());
		if(opinionTypes!=null && CollectionUtils.isNotEmpty(opinionTypes.get(4))){
			return opinionTypes.get(4);
		}
		return null;
	}

}
